import axios from 'axios';
import qs from 'qs';
let http = {
	apiurl: function(action) {
		var siteInfo = {
			uniacid: '52',
			siteroot: "https://open.ls11.cn/app/index.php",
		};
		var siteInfo = siteInfo;
		var url = siteInfo.siteroot + '?i=' + siteInfo.uniacid + '&c=entry&a=webapp&m=lshd_zhaopinhign&do=' + action;
		return url;
	},
	rget: function(option, params = {}) {
		return new Promise((resolve, reject) => {
			axios.request(this.apiurl(option), params, {
					method: "get",
					timeout: 0
				})
				.then(d => {
					resolve(d.data);
				})
				.catch((e) => reject(e));
		});
	},
	rpost: function(option, data = {}) {
		return new Promise((resolve, reject) => {
			axios.request(this.apiurl(option), data, {
					method: "post",
					timeout: 0
				})
				.then(d => {
					resolve(d.data);
				})
				.catch((e) => reject(e));
		});
	},
	aget: function(option, params = {}) {
		return new Promise((resolve, reject) => {
			axios.get(this.apiurl(option), {
					params: params
				})
				.then(response => {
					resolve(response.data);
				})
				.catch(err => {
					reject(err)
				})
		})
	},
	apost: function(option, params = {}) {
		const pdate = qs.stringify(params);
		return new Promise((resolve, reject) => {
			axios.post(this.apiurl(option), pdate)
				.then(response => {
					resolve(response.data);
				}, err => {
					reject(err)
				})
		})
	}
}
export {http}